package com.itheima.server.controller;


import com.itheima.common.core.domain.AjaxResult;
import com.itheima.server.service.IndexService;
import com.itheima.server.vo.BusinessChangeStatisticsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import com.itheima.common.core.domain.AjaxResult;
import com.itheima.server.vo.IndexCluDragonTigerVo;
import org.springframework.web.bind.annotation.GetMapping;
import com.itheima.common.core.domain.AjaxResult;
import com.itheima.server.dto.IndexInfoDto;
import com.itheima.server.service.IndexService;
import com.itheima.server.vo.IndexInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {
    @Autowired
    private IndexService indexService;

    @RequestMapping("/businessChangeStatistics")
    public AjaxResult getBusinessChangeStatistics(
             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime){
        List<BusinessChangeStatisticsVo>  list = indexService.getBusinessChangeStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }

    @GetMapping
    public AjaxResult indexInfo(IndexInfoDto dto){
        IndexInfoVo infoVo = indexService.indexInfo(dto);
        return AjaxResult.success(infoVo);

    }

    @GetMapping("/salesStatistic")
    public AjaxResult getCluDragonTiger(String beginCreateTime,String endCreateTime) {
        LocalDate begin = LocalDate.parse(beginCreateTime);
        LocalDate end = LocalDate.parse(endCreateTime);
//
        List<IndexCluDragonTigerVo> cluDragonTigerVoList =indexService.getCluDragonTiger(begin,end);
        return AjaxResult.success(cluDragonTigerVoList);
    }



}
